﻿using System;

namespace ComToolkit.IO
{
    //http://msdn.microsoft.com/en-us/library/ts2t8ybh(v=VS.85).aspx
    public class DriveInfo : IDisposable
    {
        private dynamic drive;

        internal DriveInfo(dynamic drive)
        {
            this.drive = drive;
        }

        public DriveType DriveType
        {
            get { return (DriveType)drive.DriveType; }
        }

        public string DriveLetter
        {
            get { return drive.DriveLetter; }
        }

        public string VolumeName
        {
            get
            {
                try
                {
                    return drive.VolumeName;
                }
                catch
                {
                    return string.Empty;
                }
            }
        }

        public double FreeSpace
        {
            get
            {
                try
                {
                    return drive.FreeSpace;
                }
                catch
                {
                    return 0;
                }
            }

        }

        public void Dispose()
        {
            this.drive = null;
        }

        public override string ToString()
        {
            return "DriveLetter " + DriveLetter + " VolumeName " + VolumeName + " FreeSpace " + FreeSpace;
        }
    }

    public enum DriveType
    {
        Unknown = 0,
        Removable = 1,
        Fixed = 2,
        Network = 3,
        CDROM = 4,
        RAMDisk = 5,
    }
}
